/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.infodb.agent.web;

import org.avaje.agentloader.AgentLoader;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @project-name:infodb
 * @package-name:com.hyts.infodb.agent.web
 * @author:LiBo/Alex
 * @create-date:2020-03-02 12:09
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */

@RequestMapping("/agent")
@RestController
public class RefreshLoadAgentController {


    @GetMapping("/refresh")
    public boolean refresh(){
        try {
            // 操作刷新字节码操作
            boolean result = AgentLoader.
                    loadAgentByMainClass("org.apache.skywalking.apm.agent.SkyWalkingAgent","agent.service_name=firstApplication,collector.backend_service=127.0.0.1:11800,agent.plugin_base_path=D:\\AlexData\\serial_server\\skywalking-6.5.0\\apache-skywalking-apm-bin\\agent");
            //            return AgentLoader.loadAgent("D:\\code_space\\skywalking\\apache-skywalking-apm-6.6.0-src\\apache-skywalking-apm-6.6.0\\apm-sniffer\\apm-agent\\target\\" +
//                    "skywalking-agent.jar");
            // No longer recommended (does not work reliable on jar-in-jar)
            //AgentLoader.loadAgentFromClasspath("ebean-agent","debug=1");
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static void main(String[] args){
       new RefreshLoadAgentController().refresh();

    }
}
